package com.xinzhi.yjyz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinzhi.entity.Keeper;
import com.xinzhi.entity.Logistics;
import com.xinzhi.entity.Retention;
import com.xinzhi.yjyz.mapper.KeeperMapper;
import com.xinzhi.yjyz.mapper.LogisticsMapper;
import com.xinzhi.yjyz.mapper.RetentionMapper;
import com.xinzhi.yjyz.service.IKeeprtService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.K;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class KeeperServiceImpl extends ServiceImpl<KeeperMapper, Keeper> implements IKeeprtService {
    @Resource
    private KeeperMapper keeperMapper;
    @Resource
    private LogisticsMapper logisticsMapper;


    @Override
    public List findAll() {
      List list =new ArrayList();
        try {
            list.add(keeperMapper.findAll());
            if (list!=null){
                return list;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null ;
    }

    @Override
    public List namedet(String name) {
            try {
                if (name!=null) {
                    List list = new ArrayList();
                    list.add(keeperMapper.namedet(name));
                    return list;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
    }

    @Override
    public List phoneget(String phone) {

        return null;
    }

    @Override
    public List numberget(String number) {
        return null;
    }

    @Override
    public int upname(String name) {
        if (name!=null){
            Logistics logistics=logisticsMapper.oneselect2("%"+name);
            if (logistics.getKd_name().equals(name)){
                keeperMapper.upname(name);
                return 1;
            }else {
                return 0;
            }
        }else {
            return 0;
        }
    }

    @Override
    public int upphone(String phone) {
        if (phone!=null){
     Logistics logistics=logisticsMapper.oneselect1("%"+phone);
     if (logistics.getKd_phone().length()==11){
         keeperMapper.upphone("%"+phone);
         return 1;
     }else {
         return 0 ;
     }
        }
        return 0;
    }
    @Override
    public int upnumber(String number) {
        if (number != null) {
            Keeper oneselect =keeperMapper.oneselect("%-" + number);
            System.out.println(oneselect.getKds_number());
            if (oneselect!=null&&oneselect.getKds_number().equals("1-4-"+number)){
             keeperMapper.upnumber("%-"+number);
                 return 1;
            }else {
               return 0;
           }
        }
        return 0;
    }

    @Override
    public Keeper oneselect(String number) {
        return null;
    }
}
